home *** CD-ROM | disk | FTP | other *** search
- .PAGE ,132
- .TITLE Move To - move a string to a character
- % .MODEL memmodel,C ; OS/2 Function
-
-
-
- ; This function moves characters from the source to the destination until the
- ; terminating character, termch, is encountered in the source string or maxlen
- ; characters are transferred. The terminating character is not transferred. At
- ; the conclusion of the transfer, the function returns the NEXT location in the
- ; destination string. A zero byte does NOT stop the transfer unless this function
- ; is assembled wity STOP_ON_ZERO_BYTE defined (see below)
-
- ;In c this would be:
-
- ; ptr = moveto(destination, source, maximum_length, terminating char);
- ; [ char destination, source ]
- ; [ int maximum_length ]
- ; [ char terminating character]
- ;No checks are made as to the validity of the string addresses. No stack checks
- ;are made on entry, testing for stack overflow etc... You have been warned
-
- ;Programmed By: A. L. Bender, M. D.
- ; January 22, 1992
- ; [Used in insurance form print routine]
- ;
- ; If transfer is to stop on a zero byte ('\0') then STOP_ON_ZERO_BYTE should
- ; be defined either by an EQU here or by a /DSTOP_ON_ZERO_BYTE on the control
- ; statement.
- .CODE ; This function has no data segment
- .LALL
- movetto PROC USES SI DI CX ES DS, dest:PTR BYTE, source:PTR BYTE, maxlen:WORD,\
- termch:BYTE
- PUSHF ; Save the flags
- ; Segment registers saved already
- CLD ; set to go forwards thru the source
- IF @DataSize ; Compile the proper instructions
- LES DI,[dest] ; get destination pointer
- LDS SI,[source] ; get source pointer
- ELSE ; For the appropriate memory model
- MOV DI,[dest] ; same but small model
- MOV SI,[source] ;
- ENDIF
- MOV CX,[maxlen] ; get maximum length
- TEST CX,CX ; If no characters are to be moved
- JZ @2 ; Immediately leave
- MOV AH,[termch] ; get the terminating character
- @1: LODSB ; loop moving characters
- CMP AL,AH ; got it yet?
- JZ @2 ; yup!
- STOSB ; no, store this character
- IFDEF STOP_ON_ZERO ; conditional assembly
- TEST AL,AL ; this code stops transfer on zero
- JZ @2 ; byte when encountered
- ENDIF
- LOOP @1 ; loop till done
- @2: MOV AX,DI ; Set the pointer up for exit
- IF @DataSize ; Just an offset if small model
- MOV DX,ES ; Segment part of address
- ENDIF
- POPF ; Restore flags (Direction may have been altered?)
- RET
- moveto ENDP
- END
-